package com.rtx.edi.platform.quartz.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.platform.quartz.bean.JobEntity;


/**
 * 定时任务dao
 * @project  rtx_xstep_api
 * @author   wujunming
 * @data     2018年3月28日上午10:55:13
 */
@Mapper
public interface JobMapper extends BaseMapper {

	/**
	 * 查询所有定时任务信息
	 * @return
	 * @throws Exception
	 */
	@Select("<script>SELECT qrtz_job_details.JOB_NAME,qrtz_job_details.description,qrtz_job_details.JOB_GROUP, qrtz_job_details.JOB_CLASS_NAME, qrtz_triggers.TRIGGER_NAME, qrtz_triggers.TRIGGER_GROUP, qrtz_cron_triggers.CRON_EXPRESSION, qrtz_cron_triggers.TIME_ZONE_ID, qrtz_triggers.trigger_state FROM qrtz_job_details JOIN qrtz_triggers ON qrtz_job_details.JOB_NAME = qrtz_triggers.JOB_NAME JOIN qrtz_cron_triggers ON qrtz_triggers.TRIGGER_NAME = qrtz_cron_triggers.TRIGGER_NAME AND qrtz_triggers.TRIGGER_GROUP = qrtz_cron_triggers.TRIGGER_GROUP where 1=1 <if test=\"JOB_NAME != null and JOB_NAME != ''\" > and qrtz_job_details.JOB_NAME like concat(concat('%',#{JOB_NAME,jdbcType=VARCHAR}),'%')</if></script>")
	@Results({ @Result(property = "jobName", column = "job_name"),
			@Result(property = "description", column = "description"),
			@Result(property = "jobGroup", column = "job_group"),
			@Result(property = "jobClassName", column = "job_class_name"),
			@Result(property = "triggerName", column = "trigger_name"),
			@Result(property = "triggerGroup", column = "trigger_group"),
			@Result(property = "cronExpression", column = "cron_expression"),
			@Result(property = "timeZoneId", column = "time_zone_id") ,
			@Result(property = "triggerState", column = "trigger_state") })
	List<JobEntity> findAll(@Param("JOB_NAME")String JOB_NAME) throws Exception;

	/**
	 * 分页查询
	 * @param pageParam
	 * @param description
	 */
	@Select("<script>SELECT qrtz_job_details.JOB_NAME,qrtz_job_details.description,qrtz_job_details.JOB_GROUP, qrtz_job_details.JOB_CLASS_NAME, qrtz_triggers.TRIGGER_NAME, qrtz_triggers.TRIGGER_GROUP, qrtz_cron_triggers.CRON_EXPRESSION, qrtz_cron_triggers.TIME_ZONE_ID, qrtz_triggers.trigger_state " +
			"FROM qrtz_job_details JOIN qrtz_triggers ON qrtz_job_details.JOB_NAME = qrtz_triggers.JOB_NAME JOIN qrtz_cron_triggers ON qrtz_triggers.TRIGGER_NAME = qrtz_cron_triggers.TRIGGER_NAME AND qrtz_triggers.TRIGGER_GROUP = qrtz_cron_triggers.TRIGGER_GROUP " +
			"where 1=1 <if test=\"description != null and description != ''\" > and qrtz_job_details.description like concat(concat('%',#{description,jdbcType=VARCHAR}),'%')</if></script>")
	@Results({ @Result(property = "jobName", column = "job_name"),
			@Result(property = "description", column = "description"),
			@Result(property = "jobGroup", column = "job_group"),
			@Result(property = "jobClassName", column = "job_class_name"),
			@Result(property = "triggerName", column = "trigger_name"),
			@Result(property = "triggerGroup", column = "trigger_group"),
			@Result(property = "cronExpression", column = "cron_expression"),
			@Result(property = "timeZoneId", column = "time_zone_id") ,
			@Result(property = "triggerState", column = "trigger_state") })
	List<JobEntity> pageList(Page<JobEntity> pageParam, @Param("description")String description);
}
